package com.next

class Address
{
    Country country
    Province province
    City city
    District district
    String address
    String zip

    AddressType type

    Activity activity
    Account account
    Contact contact
    Campaign campaign
    Opportunity opportunity
    Lead lead
    Contract contract

    Date createdDate = new Date()
    Date modifiedDate = new Date()

    static constraints = {
        address maxSize: 256
        zip maxSize: 16

        country nullable: true, blank: true
        province nullable: true, blank: true
        city nullable: true, blank: true
        district nullable: true, blank: true
        zip nullable: true, blank: true

        activity nullable: true, blank: true
        account nullable: true, blank: true
        contact nullable: true, blank: true
        campaign nullable: true, blank: true
        opportunity nullable: true, blank: true
        lead nullable: true, blank: true
        contract nullable: true, blank: true

        createdDate nullable: true, blank: true
        modifiedDate nullable: true, blank: true
    }

    static mapping = {
        sort 'country', 'province', 'city', 'district', 'address'
    }

    def beforeUpdate()
    {
        modifiedDate = new Date()
    }

    String toString()
    {
        // '${type} - ${address}'
        "${type} - ${address}"
    }
}
